import request from "@/utils/request";

const BASE_URL = "/api/v1";
const GoodAPI = {
  /**
   * 获取商品列表
   * @param pageNum 页码
   * @param pageSize 每页条数
   * @returns 商品列表
   */
  getGoodsList({
    pageNum,
    pageSize,
    categoryId,
    companyId,
  }: {
    pageNum: number;
    pageSize: number;
    categoryId: string;
    companyId: number;
  }) {
    return request<any, any>({
      url: `${BASE_URL}/companyIndexGoods/page`,
      method: "post",
      data: {
        pageNum,
        pageSize,
        categoryId,
        companyId,
      },
    });
  },
  /**
   * 添加商品
   * @param data 商品数据
   * @returns 添加结果
   */
  addGood(data: any) {
    return request<any, any>({
      url: `${BASE_URL}/companyIndexGoods/add`,
      method: "post",
      data,
    });
  },
  /**
   * 编辑商品
   * @param data 商品数据
   * @returns 编辑结果
   */
  editGood(data: any) {
    return request<any, any>({
      url: `${BASE_URL}/companyIndexGoods/edit`,
      method: "put",
      data,
    });
  },
  /**
   * 删除商品
   * @param id 商品id
   * @returns 删除结果
   */
  deleteGood(ids: string) {
    return request<any, any>({
      url: `${BASE_URL}/companyIndexGoods/delete/${ids}`,
      method: "delete",
    });
  },
  /**
   * 获取商品分类列表
   * @returns 商品分类列表
   */
  getGoodsCategoryList(parentCode: string = "zhuangXiuJianCai") {
    return request<any, any>({
      url: `${BASE_URL}/common/materialCategory`,
      method: "get",
      params: {
        parentCode,
      },
    });
  },
};

export default GoodAPI;
